package cn.midas.basic.controller;

import cn.midas.basic.dto.RejisterDto;
import cn.midas.basic.exception.BusinessException;
import cn.midas.basic.service.IGraphCodeService;
import cn.midas.basic.utils.AjaxResult;
import cn.midas.org.domain.Shop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/graphCode")
public class GraphCodeController {

    @Autowired
    private IGraphCodeService graphCodeService;
    /*/**
    * @Title: graph
    * @Description: 获取图形验证码
    * @Author: Mr.She
    * @Version: 1.0
    * @Date:  2022/7/6 15:28  
    * @Parameters: [imageCodeKey]
    * @Return cn.midas.basic.utils.AjaxResult
    */
    @GetMapping ("/image/{imageCodeKey}") // 请求地址：http://localhost:8080/department/1 GET请求
    public AjaxResult graph(@PathVariable("imageCodeKey") String imageCodeKey){
        try {
            String base64Str = graphCodeService.graph(imageCodeKey);
            return AjaxResult.me().setResultObj(base64Str);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请重试！");
        }
    }
    /*/**
    * @Title: settlement
    * @Description: 获取手机验证码
    * @Author: Mr.She
    * @Version: 1.0
    * @Date:  2022/7/6 15:28  
    * @Parameters: [rejisterDto]
    * @Return cn.midas.basic.utils.AjaxResult
    */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody RejisterDto rejisterDto){
        try {
            graphCodeService.smsCode(rejisterDto);
            return AjaxResult.me();
        } catch (BusinessException e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请重试！");
        }
    }
}
